package com.gulimall.member.controller;

import com.gulimall.api.domain.CouponDTO;
import com.gulimall.api.feign.CouponClient;
import com.gulimall.common.core.domain.Result;
import com.gulimall.member.domain.dto.PeopleDTO;
import com.gulimall.member.domain.entity.Member;
import com.gulimall.member.service.IMemberService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test/member")
public class TestController {
    @Resource
    private CouponClient couponClient;
    @Resource
    private PeopleDTO peopleDTO;
    @Resource
    private IMemberService memberService;

    @GetMapping("/coupon")
    public Result<CouponDTO> getCoupon(){
        CouponDTO couponDTO = couponClient.getCouponDTO();
        return Result.ok(couponDTO);
    }

    @GetMapping("/config")
    public Result<PeopleDTO> getConfig(){
        return Result.ok(peopleDTO);
    }

    /**
     * 保存单个用户到数据库
     */
    @PostMapping("/save")
    public Result saveMember(){
        Member member = new Member();
        member.setCity("上海");
        memberService.save(member);
        return Result.ok();
    }
}
